package cn.me.sso.client.utils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * @author zchcpywin10
 */
public class TypeCheck {
  public static void main(String[] args) {
    testMap();
    testList();
  }
  private static void testMap() {
    Map<String, Object> mapOriginalFoo = new HashMap<>();
    Map<String, Integer> mapOriginalSon = new HashMap<>();
    mapOriginalSon.put("a", 1);
    mapOriginalSon.put("b", 2);
    mapOriginalSon.put("c", 3);
    mapOriginalFoo.put("aa", mapOriginalSon);
    if (mapOriginalFoo.get("aa") instanceof Map<?, ?>) {
      Map<?, ?> map_current_foo = (Map<?, ?>) mapOriginalFoo.get("aa");
      Class keyClass = map_current_foo.entrySet().stream().findFirst().map(entry -> entry.getKey().getClass()).orElse(null);
      Class valueClass = map_current_foo.entrySet().stream().findFirst().map(entry -> entry.getValue().getClass()).orElse(null);
      if (String.class.equals(keyClass) && Integer.class.equals(valueClass)) {
        Map<String, Integer> map_current_son = new HashMap<>();
        for (Map.Entry entry : map_current_foo.entrySet()) {
          String key = (String) entry.getKey();
          Integer value = (Integer) entry.getValue();
          map_current_son.put(key, value);
        }
        System.out.println(map_current_son);
      }
    }
  }
  private static void testList() {
    Map<String, Object> map_original_foo = new HashMap<>();
    List<String> list_original_son = new ArrayList<>();
    list_original_son.add("aa");
    list_original_son.add("bb");
    list_original_son.add("cc");
    map_original_foo.put("dd", list_original_son);
    if (map_original_foo.get("dd") instanceof List<?>) {
      List<?> temp_list = (List<?>) map_original_foo.get("dd");
      Class valueClass = temp_list.stream().findFirst().map(Object::getClass).orElse(null);
      if (String.class.equals(valueClass)) {
        List<String> list_current_son = new ArrayList<>();
        for (Object s : temp_list) {
          String value = (String) s;
          list_current_son.add(value);
        }
        System.out.println(list_current_son);
      }
    }
  }
}
